package com.xju.atpgs.service.Impl;

import com.xju.atpgs.entity.Dictionary;
import com.xju.atpgs.entity.DictionaryExample;
import com.xju.atpgs.entity.User;
import com.xju.atpgs.mapper.DictionaryMapper;
import com.xju.atpgs.mapper.UserMapper;
import com.xju.atpgs.service.DictionaryService;
import com.xju.atpgs.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    DictionaryMapper dictionaryMapper;



    @Override
    public Dictionary findById(String id) {
        DictionaryExample dictionaryExample=new DictionaryExample();
        dictionaryExample.createCriteria().andDicIdEqualTo(id);
        return dictionaryMapper.selectByExample(dictionaryExample).get(0);
    }

    @Override
    public Dictionary findByValue(String value) {
        DictionaryExample dictionaryExample=new DictionaryExample();
        dictionaryExample.createCriteria().andDicValueEqualTo(value);
        return dictionaryMapper.selectByExample(dictionaryExample).get(0);
    }

    @Override
    public void insert(Dictionary dictionary) {
        dictionaryMapper.insert(dictionary);
    }

    @Override
    public List<Dictionary> searchByType(String type) {
        DictionaryExample dictionaryExample=new DictionaryExample();
        dictionaryExample.createCriteria().andDicTypeNameEqualTo(type);
        return dictionaryMapper.selectByExample(dictionaryExample);
    }

    @Override
    public Dictionary findByTypeAndValue(String type, String value) {
        DictionaryExample dictionaryExample=new DictionaryExample();
        dictionaryExample.createCriteria().andDicTypeNameEqualTo(type).andDicValueEqualTo(value);
        return dictionaryMapper.selectByExample(dictionaryExample).get(0);
    }
}
